package com.applink.sell_proof.model;

import java.util.ArrayList;

import com.applink.sell_proof.pojo.GenericAttribute;
import com.applink.sell_proof.share.Parameter;
import com.applink.sell_proof.utilXMLParser.ObjPropInfo;

public class NewRewardClaim {
	private int idClaim;
	private int ProgramID;
	private String ProgramName;
	private String Quarter;
	private String Year;
	private String ProgramCode;
	private String ProductCategoryName;
	private String TotalRewardAmount;
	private String TotalQuantity;
	private String Period;
	private int ProductCategoryID;

	// private int ObjectID;

	public int getIdClaim() {
		return idClaim;
	}

	public void setIdClaim(int idClaim) {
		this.idClaim = idClaim;
	}

	public int getProgramID() {
		return ProgramID;
	}

	public void setProgramID(int programID) {
		ProgramID = programID;
	}

	public String getProgramName() {
		return ProgramName;
	}

	public void setProgramName(String programName) {
		ProgramName = programName;
	}

	public String getQuarter() {
		return Quarter;
	}

	public void setQuarter(String quarter) {
		Quarter = quarter;
	}

	public String getYear() {
		return Year;
	}

	public void setYear(String year) {
		Year = year;
	}

	public String getProgramCode() {
		return ProgramCode;
	}

	public void setProgramCode(String programCode) {
		ProgramCode = programCode;
	}

	public String getProductCategoryName() {
		return ProductCategoryName;
	}

	public void setProductCategoryName(String productCategoryName) {
		ProductCategoryName = productCategoryName;
	}

	public String getTotalRewardAmount() {
		return TotalRewardAmount;
	}

	public void setTotalRewardAmount(String totalRewardAmount) {
		TotalRewardAmount = totalRewardAmount;
	}

	public String getTotalQuantity() {
		return TotalQuantity;
	}

	public void setTotalQuantity(String totalQuantity) {
		TotalQuantity = totalQuantity;
	}

	public void setPeriod(String period) {
		Period = period;
	}

	public String getPeriod() {
		return Period;
	}

	// public int getObjectID() {
	// return ObjectID;
	// }
	// public void setObjectID(int objectID) {
	// ObjectID = objectID;
	// }
	public int getCategoryId() {
		return ProductCategoryID;
	}

	public void setCategoryId(int categoryId) {
		ProductCategoryID = categoryId;
	}

	@SuppressWarnings("rawtypes")
	public ArrayList<GenericAttribute> convertIntoGenericAttributes(
			ArrayList<ObjPropInfo> objPropList) {

		ArrayList<GenericAttribute> attributeList = new ArrayList<GenericAttribute>();

		for (int i = 0; i < objPropList.size(); i++) {
			ObjPropInfo objPropInfo = objPropList.get(i);

			String name = objPropInfo.getOPID();
			String dataType = objPropInfo.getDataType();

			String value = this.getValueByName(name);

			if (value == "") {
				value = "0";
			}
			if (dataType.compareTo(Parameter.TYPE_INT) == 0) {
				GenericAttribute<String, Integer> attribute = new GenericAttribute<String, Integer>(
						name, (int) Long.parseLong(value));
				attributeList.add(attribute);
			} else if (dataType.compareTo(Parameter.TYPE_CHAR) == 0) {
				GenericAttribute<String, String> attribute = new GenericAttribute<String, String>(
						name, String.valueOf(value));
				attributeList.add(attribute);
			} else if (dataType.compareTo(Parameter.TYPE_DOUBLE) == 0) {
				GenericAttribute<String, Double> attribute = new GenericAttribute<String, Double>(
						name, Double.parseDouble(value));
				attributeList.add(attribute);
			}

		}

		return attributeList;
	}

	public String getValueByName(String name) {

		String value = "";
		Object instance;
		try {
			instance = getClass().getDeclaredField(name).get(this);
			value = instance.toString();
		} catch (Exception e) {
			value = "";
		}
		return value;
	}
}
